home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / C / nodeFuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.5 KB  |  257 lines

  1.  
  2. /*    
  3.  *        nodeFuncs
  4.  *    
  5.  *        All node routines more complicated than simple access/modification
  6.  *        $Header: /private/postgres/src/lib/C/RCS/nodeFuncs.c,v 1.22 1992/07/04 04:03:38 mao Exp $
  7.  */
  8.  
  9. #include "tmp/c.h"
  10.  
  11. RcsId("$Header: /private/postgres/src/lib/C/RCS/nodeFuncs.c,v 1.22 1992/07/04 04:03:38 mao Exp $");
  12.  
  13. #include "nodes/primnodes.h"
  14. #include "nodes/plannodes.h"
  15. #include "nodes/nodes.h"
  16. #include "nodes/pg_lisp.h"
  17. #include "nodes/relation.h"
  18. #include "tmp/nodeFuncs.h"
  19.  
  20. #include "planner/keys.h"
  21.  
  22.  
  23. /*    
  24.  *        single_node
  25.  *    
  26.  *        Returns t if node corresponds to a single-noded expression
  27.  *    
  28.  */
  29.  
  30. /*  .. contains-not, fix-opid, flatten-tlistentry, nested-clause-p
  31.  *  .. pull_var_clause, relation-level-clause-p, replace-clause-joinvar-refs
  32.  *  .. replace-clause-nestvar-refs, replace-clause-resultvar-refs
  33.  *  .. valid-or-clause
  34.  */
  35. bool
  36. single_node (node)
  37.      Node node ;
  38. {
  39.     if(atom (node) || IsA(node,Const) || IsA(node,Var) || IsA(node,Param)) 
  40.       return(true);
  41.     else
  42.       return(false);
  43. }
  44.  
  45. /*        =========
  46.  *        VAR nodes
  47.  *        =========
  48.  */
  49.  
  50. /*    
  51.  *        var_is_outer
  52.  *        var_is_inner
  53.  *        var_is_mat
  54.  *        var_is_rel
  55.  *    
  56.  *        Returns t iff the var node corresponds to (respectively):
  57.  *        the outer relation in a join
  58.  *        the inner relation of a join
  59.  *        a materialized relation
  60.  *        a base relation (i.e., not an attribute reference, a variable from
  61.  *            some lower join level, or a sort result)
  62.  *      var node is an array reference
  63.  *    
  64.  */
  65.  
  66. /*  .. ExecEvalVar, switch_outer, var_is_rel   */
  67.  
  68. bool
  69. var_is_outer (var)
  70.      Var var ;
  71. {
  72.     return((bool)(get_varno (var) == OUTER));
  73. }
  74.  
  75. /*  .. ExecEvalVar, var_is_rel   */
  76.  
  77. bool
  78. var_is_inner (var)
  79.      Var var ;
  80. {
  81.     return ( (bool) (get_varno (var) == INNER));
  82. }
  83.  
  84. /*  .. get_relattval, get_relsatts  */
  85.  
  86. /* XXX - completely bogus, Var needs an extra flags that is 
  87.    "materialized ?" */
  88.  
  89. bool
  90. var_is_mat (var)
  91.      Var var ;
  92. {
  93.     return (false);
  94.     /* return((bool)listp (get_varno(var))); */
  95. }
  96.  
  97. /*  .. ExecEvalVar  */
  98.  
  99. bool
  100. var_is_rel (var)
  101.      Var var ;
  102. {
  103.     return (bool)
  104.     ! (var_is_inner (var) ||  var_is_outer (var));
  105. }
  106.  
  107. /*        ==========
  108.  *        OPER nodes
  109.  *        ==========
  110.  */
  111.  
  112. /*    
  113.  *        replace_opid
  114.  *    
  115.  *        Given a oper node, resets the opfid field with the
  116.  *        procedure OID (regproc id).
  117.  *    
  118.  *        Returns the modified oper node.
  119.  *    
  120.  */
  121.  
  122. /*  .. fix-opid, index-outerjoin-references, replace-clause-joinvar-refs
  123.  *  .. replace-clause-resultvar-refs
  124.  */
  125.  
  126. Oper
  127. replace_opid (oper)
  128.      Oper oper ;
  129. {
  130.     set_opid (oper,get_opcode (get_opno (oper)));
  131.     set_op_fcache(oper, NULL); 
  132.     return(oper);
  133. }
  134.  
  135. /*        =============================
  136.  *        constant (CONST, PARAM) nodes
  137.  *        =============================
  138.  */
  139.  
  140. /*    
  141.  *        constant-p
  142.  *    
  143.  *        Returns t iff the argument is a constant or a parameter.
  144.  *    
  145.  */
  146.  
  147. /*  .. get_relattval, match-index-orclause, qual-clause-p, single_node
  148.  */
  149.  
  150. bool
  151. constant_p (node)
  152.      Expr node ;
  153. {
  154.     if ( IsA(node,Const) || IsA(node,Param) )
  155.       return(true);
  156.     else
  157.       return(false);
  158. }
  159.  
  160. /*    
  161.  *        non_null
  162.  *    
  163.  *        Returns t if the node is a non-null constant, e.g., if the node has a
  164.  *        valid `constvalue' field.
  165.  *    
  166.  */
  167.  
  168. /*  .. MakeAttlist, best-or-subclause-index, get_relattval, is_null
  169.  */
  170.  
  171. bool
  172. non_null (c)
  173.      Expr c;
  174. {
  175.  
  176.     if ( IsA(c,Const) && !get_constisnull ((Const)c) )
  177.       return(true);
  178.     else
  179.       return(false);
  180.  
  181.  
  182. }
  183.  
  184. /*    
  185.  *        is_null
  186.  *    
  187.  *        Returns t if the node is anything but a non-null constant (has no valid
  188.  *        `constvalue' field).
  189.  *    
  190.  */
  191.  
  192. /*  .. ExecEvalNot, ExecEvalOr, ExecIsNull, ExecQual1, print_const
  193.  */
  194.  
  195. bool
  196. is_null (constant)
  197.      Expr constant ;
  198. {
  199.     if (!non_null (constant))
  200.       return(true);
  201.     else
  202.       return(false);
  203.  
  204. }
  205.  
  206. /*        ==========
  207.  *        PLAN nodes
  208.  *        ==========
  209.  */
  210.  
  211. /*  .. print_subplan, set-tlist-references
  212.  */
  213. bool
  214. join_p (node)
  215.      Node node ;
  216. {
  217.     if( IsA(node,NestLoop) || IsA(node,HashJoin) || IsA(node,MergeJoin))
  218.       return(true);
  219.     else
  220.       return(false);
  221. }
  222.  
  223. /*  .. print_subplan
  224.  */
  225.  
  226. bool
  227. scan_p (node)
  228.      Node node ;
  229. {
  230.     if( IsA(node,SeqScan) || IsA(node,IndexScan))
  231.       return(true);
  232.     else
  233.       return(false);
  234. }
  235.  
  236. /*  .. print_subplan, query_planner, set-tlist-references
  237.  */
  238. bool
  239. temp_p (node)
  240.      Node node ;
  241. {
  242.     if ( IsA(node,Sort) || IsA(node,Hash))
  243.       return(true);
  244.     else
  245.       return(false);
  246. }
  247.  
  248. bool
  249. plan_p (node)
  250.      Node node ;
  251. {
  252.     if ( IsA(node,Result) || IsA(node,Existential))
  253.       return(true);
  254.     else
  255.       return(false);
  256. }
  257.